<template>
  <!--待办集成-->
  <el-container>
    <basic-crud   v-loading="resetAllLoading" element-loading-text="正在执行，这个功能耗时比较长"
                  ref="crudRef" :option="option" businessUrl="/mes/mesUndoTaskController"
                selectType="multiple">
      <template #menu-left>
        <el-button
            type="primary" plain
            :loading="resendLoading"
            @click="resend"
            icon="upload"
        >重发</el-button>
        <el-button
            type="primary" plain
            :loading="resendAndFinishLoading"
            @click="resendAndFinish"
            icon="upload"
        >重发并完成</el-button>
        <el-button
            type="primary" plain
            :loading="resetAllLoading"
            @click="resetAll"
            icon="refresh"
        >重置全部待办</el-button>
      </template>
    </basic-crud>
  </el-container>
</template>

<script setup>
import {ref} from "vue";
import {resendApi, resendAndFinishApi, resetAllApi} from "@/apis/integration/undo/undoApi";

const option = {
  height: "auto",
  calcHeight: 10,
  selection: true,
  addBtn: false,
  delBtn: false,
  editBtn: false,
  searchIndex: 3,
  searchIcon: true,
  menuWidth:70,
  column: [{
    label: '工号',
    prop: 'code',
    sortable: true,
    search: true,
    width: 90,
  }, {
      label: '姓名',
      prop: 'name',
      sortable: true,
      width: 90
    },
    {
      label: '任务主键',
      prop: 'taskId',
      sortable: true,
      width: 170
    },
    {
      label: '任务业务类型',
      prop: 'taskBus',
      width: 130
    },
    {
      label: '任务信息',
      prop: 'taskInfoJson',
      minWidth: 300,
      overHidden:true,
      search:true,
      showOverfowTooltip:true
    },
    {
      label: '任务接收人信息',
      prop: 'taskPersonJson',
      overHidden:true,
      minWidth: 300,
      showOverflowTooltip:true
    },
    {
      label: '集成状态',
      prop: 'inteStatus',
      sortable: true,
      search: true,
      type:'select',
      dicData:[{
        label:'成功',
        value:'success'
      },{
        label: '失败',
        value:'fail'
      },{
        label: '未处理',
        value:'undo'
      }],
      width: 90
    },
    {
      label: '操作类型',
      prop: 'inteOperate',
      sortable: true,
      search: true,
      type:'select',
      dicData:[{
        label:'添加',
        value:'add'
      },{
        label: '更新',
        value:'update'
      }],
      width: 90
    },
    {
      label: '错误信息',
      prop: 'errorInfo',
    }]
}
const crudRef = ref(null)

const resendLoading = ref(false)
const resend=()=>{
  if (crudRef.value.selectData.length == 0) {
    return ElMessage.warning('至少选择一条数据！')
  }
  resendApi(crudRef.value.selectData,resendLoading).then(res=>{
    ElMessage.success("重发成功");
    crudRef.value.getList();
  })
}

const resendAndFinishLoading = ref(false)
const resendAndFinish=()=>{
  if (crudRef.value.selectData.length == 0) {
    return ElMessage.warning('至少选择一条数据！')
  }
  resendAndFinishApi(crudRef.value.selectData,resendAndFinishLoading).then(res=>{
    ElMessage.success("重发成功");
    crudRef.value.getList();
  });
}

const resetAllLoading = ref(false)
const resetAll=()=>{
  resetAllApi(resetAllLoading).then(res=>{
    ElMessage.success("重置全部待办成功");
    crudRef.value.getList();
  });
}
</script>

<style scoped>

</style>